﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HCommon;
namespace eStock.hControl
{
    public partial class hFindBox : hForm
    {
        private string pMajorCd;
        public DataGridViewRow gRow;// = new DataGridViewRow();
        private DataTable pData;
        public hFindBox(DataTable dtData, string MajorCd, string qryCondition)
        {
            InitializeComponent();
            pData = dtData;
            pMajorCd = MajorCd;
            txtID.Text = qryCondition;
        }

        private void btnFind_Click(object sender, EventArgs e)
        {
            try
            {
                DataTable dt = new DataTable();
                dt = Dao.Get_Table("Exec spLoadFB '" + Common.xoaNhay(pMajorCd) + "',N'" + Common.xoaNhay(txtID.Text) + "'");
                grdList.DataSource = dt;
                grdList.Focus();
            }
            catch (Exception ex)
            {
                Common.GhiLog("btnFind_Click", ex);
                Dialog.ShowMess(Dialog.mType.err, ex.Message);
            }

        }

        private void grdList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (grdList.Rows.Count == 0 || e.RowIndex < 0)
                {
                    return;
                }

                gRow = grdList.Rows[e.RowIndex];
                this.Close();
            }
            catch (Exception ex)
            {
                Common.GhiLog("grdList_CellDoubleClick", ex);
                Dialog.ShowMess(Dialog.mType.err, ex.Message);
            }
        }

        private void hFindBox_Load(object sender, EventArgs e)
        {
            try
            {
                grdList.DataSource = pData;
                if (grdList.Rows.Count == 1)
                {
                    gRow = grdList.Rows[0];
                }
            }
            catch { }
        }

        private void grdList_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    if (grdList.Rows.Count == 0 || grdList.CurrentCell.RowIndex < 0)
                    {
                        return;
                    }
                    gRow = grdList.CurrentRow;
                    this.Close();
                }
            }
            catch { }
        }
    }
}
